<html>
  <head>
    <title>Match Food Description</title>
    <link rel='stylesheet' type='text/css' href='sr23.css' />
  </head>  
  
  <body>
  <div id='match_food_form'>
    <form method='get' name='match_food_description'>
      <table>
        <tbody>  
          <tr>  
            <th>Food Description:</th>
            <td><input type='text' name='mf' size='25'></p>
          </tr>
          <tr>  
            <td colspan='2'><input type='submit' value='match food description'/></td>
          </tr>
        </tbody>
      </table>      
    </form>
  </div>    

<?php
require_once 'sr23_model.php';

$sr23 = new sr23_model();

if ($_GET['n']) {
    $hash = $sr23->get_nutrient($_GET['n']);
}
?>

  <div id='match_food_results'>
<?php
if ($_GET['mf']) {
    // check to be sure that string is preceded and ended by quotes
    if (!preg_match("/^\"(.+)\"$/",$_GET['mf'])) {
        $mf = '"' . $_GET['mf'] . '"';
    }
    else
    {
        $mf = $_GET['mf'];
    }

    print "<p>searching for $mf</p>";
    $food_array = $sr23->match_description($mf);
    
    // $sr23->print_pretty_array($food_arrray);
    if (count($food_array) > 0) {
        print '<table><tbody>';
    
            foreach ($food_array as $hash) {
                print '<tr>';
                foreach ($hash as $k => $v) {
                    print "<td>$v</td>";
                }
                // print out the link
                print "<td><a href='calculate.php?n=" . str_replace("~","",$hash['NDB_No']) . "'>calculate</a></td>";
                print '</tr>';
            }
        print '</tbody></table>';
    }
    else
    {
        print "<p>no matches for $mf found.</p>";
    }
    
}
?>
  </div>
</body>
</html>    
